﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.CampanyCMS.Business.Bus;
using System.Collections.Generic;
using Eis51.CampanyCMS.FrameWork;
using Eis51.CampanyCMS.Business.BaseInfoMng;

namespace Eis51.CampanyCMS.WebUI.Admin.Order
{
    public partial class vieworderDetail : System.Web.UI.Page
    {
        public string OrderSeqno
        {
            get
            {
                return Request.QueryString["OrderSeqno"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }

        private void InitData()
        {
           IList lst = OrderApplyItemBLL.GetInstance().SearchByOrderSeqno(OrderSeqno);
            this.rpCarList.DataSource = lst;
            this.rpCarList.DataBind();



            if (OrderSeqno != string.Empty)
            {
                OrderApply obj = OrderApplyBLL.GetInstance().Get(new OrderApply.Key(int.Parse(OrderSeqno)));
                lblOrderNO.Text = obj.OrderNo;
                lblOrderStatus.Text = Dict.Tag[(OrderStatusType)obj.OrderStatus];

                lblRemark.Text = obj.Remark;
                lblreceive_Address.Text = obj.ReceiveAddress;
                lblreceive_Name.Text = obj.ReceiveName;
                lblReceivePhone.Text = obj.ReceivePhone;
                lblReceiveEmail.Text = obj.ReceiveEmail;
                lblReceiveTel.Text = obj.ReceiveTel;
                lblShipment.Text = obj.Shipment;
                lblZip.Text = obj.Zip;
                lblreceive_Address1.Text = obj.ReceiveAddress1;
                lblPayName.Text = obj.Mypayment;

                if (obj.PreferentialMoney > 0)
                {
                    txtPreferent.Text = obj.PreferentialMoney.ToString("0.00");
                    lblPreferential_Money.Text = obj.PreferentialMoney.ToString("0.00");
                }
                //总金额
                if (obj.MailMoney > 0)
                {
                    lblMailMoney.Text = obj.MailMoney.ToString("0.00");
                }
                if (obj.ProductTMoney > 0)
                {
                    lblProduTMoney.Text = obj.ProductTMoney.ToString("0.00");
                }
                lblAllTotal.Text = obj.TotalMoney.ToString("0.00");

                //只有待付款可以修改订单价
                if (obj.OrderStatus != (int)OrderStatusType.WatiPay)
                {
                    this.lbtnPreferentModify.Visible = false;
                }
 
            }
            else
            {
                lbtnPreferentModify.Visible = false;
                lbtnPreferentSave.Visible = false;
            }
        }

        protected void lbtnPreferentModify_Click(object sender, EventArgs e)
        {
            this.divPreferentialEdit.Visible = true;
            this.divPreferentialView.Visible = false;

        }

        protected void lbtnPreferentSave_Click(object sender, EventArgs e)
        {
            this.divPreferentialEdit.Visible = false;
            this.divPreferentialView.Visible = true;

            if (OrderSeqno != string.Empty)
            {
                OrderApply obj = OrderApplyBLL.GetInstance().Get(new OrderApply.Key(int.Parse(OrderSeqno)));
                obj.PreferentialMoney = double.Parse(txtPreferent.Text);
                lblPreferential_Money.Text = obj.PreferentialMoney.ToString("0.00");
                obj.TotalMoney = (obj.ProductTMoney + obj.MailMoney + obj.OtherMoney - obj.PreferentialMoney);
                lblAllTotal.Text = obj.TotalMoney.ToString("0.00");
                OrderApplyBLL.GetInstance().Submit(obj);
            }
        }
    }
}
